package com.banciyuan.bcywebview.biz.main.newdiscover.index.discoverholder;

import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banciyuan.bcywebview.R;
import com.banciyuan.bcywebview.biz.topic.TopicDetailActivity;
import com.banciyuan.bcywebview.biz.topic.TopicDetailListActivity;
import com.banciyuan.bcywebview.utils.intent.gotoUtil;
import com.banciyuan.bcywebview.utils.universalimageloader.core.ImageLoader;
import com.banciyuan.bcywebview.utils.universalimageloader.utils.ImageOptions;

import de.greenrobot.daoexample.model.Timeline;

/**
 * Created by hy on 2015/8/26.
 */
public class TopicSingleHolder extends BaseDiscoverHolder {

    private ImageView mainImage;
    private TextView sepcialDesc;
    private TextView specialTitle;
    private TextView topicTags;

    public TopicSingleHolder(View itemView) {
        super(itemView);
        mainImage = (ImageView) itemView.findViewById(R.id.iv_main);
        sepcialDesc = (TextView) itemView.findViewById(R.id.tv_special_desc);
        specialTitle = (TextView) itemView.findViewById(R.id.tv_special_title);
        topicTags = (TextView) itemView.findViewById(R.id.iv_label);
    }

    public void renderData(final Timeline mData, final Context context) {
        if (mData.isfirst()) {
            mFirstHeaderTitle.setText(context.getString(R.string.selected_topic));
            mFirstHeaderIntro.setText(context.getString(R.string.topic_top_slogn));
            mFirstFooterTitle.setText(context.getString(R.string.more_topic));
            mFirstHeaderContainer.setVisibility(View.VISIBLE);
            mFirstFooterContainer.setVisibility(View.VISIBLE);
        } else {
            mFirstHeaderContainer.setVisibility(View.GONE);
            mFirstFooterContainer.setVisibility(View.GONE);
        }
        itemView.findViewById(R.id.footer_split).setVisibility(View.GONE);
        ImageLoader.getInstance().displayImage(mData.getContentAddress(), mainImage, ImageOptions.options);
        if (!TextUtils.isEmpty(mData.getTitle())) {
            specialTitle.setText(Html.fromHtml(mData.getTitle()));
        }
        if (!TextUtils.isEmpty(mData.getIntro())) {
            sepcialDesc.setText(Html.fromHtml(mData.getIntro()));
        }
        if (mData.getLabels() != null && mData.getLabels().size() > 0) {
            topicTags.setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(mData.getLabels().get(0))) {
                topicTags.setText(mData.getLabels().get(0));
            }
        } else {
            topicTags.setVisibility(View.GONE);
        }
        mFirstFooterContainer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gotoUtil.gotoAct(context, TopicDetailListActivity.class);
            }
        });
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, TopicDetailActivity.class);
                intent.putExtra(gotoUtil.INTENT_VALUE_ONE, Integer.parseInt(mData.getSpecial_id()));
                context.startActivity(intent);
            }
        });
    }
}
